home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 3 / Amiga Tools 3.iso / grafik / raytracing / rayshade-4.0.6.3 / urt / amiga_extras / qrttorle / qrttorle.c < prev   
Encoding:
C/C++ Source or Header  |  1993-07-31  |  2.8 KB  |  115 lines

  1. /*
  2.  * This software is copyrighted as noted below.  It may be freely copied,
  3.  * modified, and redistributed, provided that the copyright notices are 
  4.  * preserved on all copies.
  5.  * 
  6.  * There is no warranty or other guarantee of fitness for this software,
  7.  * it is provided solely "as is".  Bug reports or fixes may be sent
  8.  * to the author, who may or may not act on them as he desires.
  9.  *
  10.  * You may not include this software in a program or other software product
  11.  * without supplying the source, or without informing the end-user that the 
  12.  * source is available for no extra charge.
  13.  *
  14.  * If you modify this software, you should include a notice giving the
  15.  * name of the person performing the modification, the date of modification,
  16.  * and the reason for such modification.
  17.  */
  18. /* 
  19.  * qrttorle.c - Convert a QRT file to an RLE image.
  20.  * 
  21.  * Author:      Kriton Kyrimis
  22.  * Based on graytorle.c by Michael J. Banks
  23.  */
  24.  
  25. #include <stdio.h>
  26. #include "rle.h"
  27.  
  28. #ifdef USE_STDLIB_H
  29. #include <stdlib.h>
  30. #else
  31.  
  32. #ifdef VOID_STAR
  33. extern void *malloc();
  34. #else
  35. extern char *malloc();
  36. #endif
  37. extern void free();
  38.  
  39. #endif /* USE_STDLIB_H */
  40.  
  41. typedef FILE    *FILPTR;
  42.  
  43. /*
  44.  * usage : qrttorle [-o outfile] [file]
  45.  *
  46.  *    -o outfile    Output file name.
  47.  */
  48.  
  49. int
  50. in(FILE *f)
  51. {
  52.   int n, l , h;
  53.   unsigned char c;
  54.  
  55.   fread((char *)&c, sizeof(c), 1, f);
  56.   l = c;
  57.   fread((char *)&c, sizeof(c), 1, f);
  58.   h = c;
  59.   n = (h << 8) + l;
  60.   return n;
  61. }
  62.  
  63. void
  64. main(int argc, char *argv[])
  65. {
  66.     char *oname = NULL;        /* Output file name. */
  67.     FILE *inpfil;        /* Input file pointer. */
  68.     int xsize, ysize;        /* Image size. */
  69.     int oflag;                /* Output file flag. */
  70.     char *fname = NULL;        /* Input file name. */
  71.     rle_pixel **outrow;        /* Output buffer. */
  72.     int i, row;
  73.  
  74.     if (! scanargs( argc,argv,
  75.         "% o%-outfile!s infile%s", &oflag, &oname, &fname ))
  76.         exit( -1 );
  77.  
  78.     /* 
  79.      * Open input file.
  80.      */
  81.  
  82.     inpfil = rle_open_f( "qrttorle", fname, "r" );
  83.     xsize = in(inpfil);
  84.     ysize = in(inpfil);
  85.  
  86.     /* Initialize the_hdr and allocate image row storage. */
  87.  
  88.     rle_dflt_hdr.alpha = 0;
  89.     rle_dflt_hdr.ncolors = 3;
  90.     rle_dflt_hdr.xmax = xsize - 1;
  91.     rle_dflt_hdr.ymax = ysize - 1;
  92.     rle_dflt_hdr.rle_file = rle_open_f("qrttorle", oname, "w");
  93.     for ( i = 0; i<rle_dflt_hdr.ncolors; i++)
  94.     RLE_SET_BIT( rle_dflt_hdr, i );
  95.     rle_addhist( argv, (rle_hdr *)NULL, &rle_dflt_hdr );
  96.     rle_put_setup( &rle_dflt_hdr );
  97.  
  98.     if (rle_row_alloc( &rle_dflt_hdr, &outrow ))
  99.     {
  100.     fprintf(stderr, "Ran out of heap space!!\n");
  101.     exit(-2);
  102.     }
  103.  
  104.     /* Combine rows and write to output file. */
  105.  
  106.     for ( row=0; row<ysize; row++)
  107.     {
  108.     (void)in(inpfil);    /* Discard scan line number */
  109.     for ( i = 0; i<3; i++ )
  110.         fread( outrow[i], 1, xsize, inpfil );
  111.     rle_putrow( outrow, xsize, &rle_dflt_hdr );
  112.     }
  113.     exit(0);
  114. }
  115.